home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog6.arj / LENGTHY.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.5 KB  |  107 lines

  1. { lengthy.pas -- Show hourglass cursor during a lengthy operation }
  2.  
  3. program Lengthy;
  4.  
  5. {$R lengthy.res}
  6.  
  7. uses WinTypes, WinProcs, WObjects;
  8.  
  9. const
  10.  
  11.   timer_ID = 1;        { Timer ID value }
  12.   timer_Interval = 1;  { Timer interval in seconds }
  13.   id_Menu = 100;       { Menu resource ID }
  14.   cm_Start = 101;      { Start command ID }
  15.   max_Time = 10;       { Length of pseudo operation in seconds }
  16.  
  17. type
  18.  
  19.   LengthyApplication = object(TApplication)
  20.     procedure InitMainWindow; virtual;
  21.   end;
  22.  
  23.   PLengthyWindow = ^LengthyWindow;
  24.   LengthyWindow = object(TWindow)
  25.     TimeRemaining: Integer;
  26.     constructor Init(AParent: PWindowsObject; ATitle: PChar);
  27.     procedure ShowTime;
  28.     procedure CMStart(var Msg: TMessage);
  29.       virtual cm_First + cm_Start;
  30.     procedure WMTimer(var Msg: TMessage);
  31.       virtual wm_First + wm_Timer;
  32.   end;
  33.  
  34.  
  35. { LengthyApplication }
  36.  
  37. {- Initialize LengthyApplication object's window }
  38. procedure LengthyApplication.InitMainWindow;
  39. begin
  40.   MainWindow := New(PLengthyWindow, Init(nil, 'Lengthy'))
  41. end;
  42.  
  43.  
  44. { LengthyWindow }
  45.  
  46. {- Construct LengthyWindow object }
  47. constructor LengthyWindow.Init(AParent: PWindowsObject;
  48.   ATitle: PChar);
  49. begin
  50.   TWindow.Init(AParent, ATitle);
  51.   Attr.Menu := LoadMenu(HInstance, PChar(id_Menu))
  52. end;
  53.  
  54. {- Display time remaining }
  55. procedure LengthyWindow.ShowTime;
  56. var
  57.   S: string[30];
  58.   DC: HDC;
  59. begin
  60.   Str(TimeRemaining, S);
  61.   S := 'Time remaining = ' + S + '    ';
  62.   DC := GetDC(HWindow);
  63.   TextOut(DC, 20, 50, @S[1], Length(S));
  64.   ReleaseDC(HWindow, DC);
  65.   MessageBeep(0)
  66. end;
  67.  
  68. {- Start pseudo lengthy operation }
  69. procedure LengthyWindow.CMStart(var Msg: TMessage);
  70. begin
  71.   SetCursor(LoadCursor(0, idc_Wait));
  72.   SetCapture(HWindow);
  73.   SetTimer(hWindow, timer_ID, timer_Interval * 1000, nil);
  74.   TimeRemaining := max_Time;
  75.   ShowTime
  76. end;
  77.  
  78. {- Intercept timer events and display hourglass cursor }
  79. procedure LengthyWindow.WMTimer(var Msg: TMessage);
  80. begin
  81.   Dec(TimeRemaining);
  82.   ShowTime;
  83.   if TimeRemaining <= 0 then
  84.   begin
  85.     KillTimer(hWindow, timer_ID);
  86.     SetCursor(LoadCursor(0, idc_Arrow));
  87.     ReleaseCapture;
  88.     MessageBox(HWindow, 'Operation completed', 'Message', mb_Ok)
  89.   end
  90. end;
  91.  
  92. var
  93.  
  94.   LengthyApp: LengthyApplication;
  95.  
  96. begin
  97.   LengthyApp.Init('LengthyApp');
  98.   LengthyApp.Run;
  99.   LengthyApp.Done
  100. end.
  101.  
  102.  
  103. {--------------------------------------------------------------
  104.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  105.   Revision 1.00    Date: 4/17/1991
  106. ---------------------------------------------------------------}
  107.